package com.car.mapper;

import com.car.pojo.EmpQueryParam;
import com.car.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户数据访问接口
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户信息
     */
    @Select("select id, username, name from user where username = #{username}")
    User selectByUsername(String username);
    
    /**
     * 根据手机号查询用户信息
     */
    @Select("select id, username, name from user where phone = #{phone}")
    User selectByPhone(String phone);

    /**
     * 根据用户名和密码查询用户信息
     */
    @Select("select id, username, name from user where username = #{username} and password = #{password}")
    User selectByUsernameAndPassword(User user);
    /**
     * 根据ID查询用户信息
     */
    @Select("select id, username, name, gender, phone, create_time, update_time from user where id = #{id}")
    User selectById(Integer id);
    
    /**
     * 条件查询用户信息
     */
    List<User> list(EmpQueryParam param);
    
    /**
     * 新增用户
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user(username, password, name, gender, phone, create_time, update_time) " +
            "values (#{username}, #{password}, #{name}, #{gender}, #{phone}, #{createTime}, #{updateTime})")
    void insert(User user);
    
    /**
     * 根据ID更新用户信息
     */
    void updateById(User user);
    
    /**
     * 根据ID批量删除用户
     */
    void deleteByIds(List<Integer> ids);
    
    /**
     * 查询所有用户
     */
    @Select("select id, username, name, gender, phone, create_time, update_time from user")
    List<User> queryAll();
}